<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模块化任务管理系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui@2.8.3/dist/css/layui.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary: #4361ee;
            --primary-light: #4895ef;
            --secondary: #3f37c9;
            --success: #4caf50;
            --warning: #ff9800;
            --danger: #e63946;
            --light: #f8f9fa;
            --dark: #212529;
            --gray: #6c757d;
            --border: #dee2e6;
            --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
            --transition: all 0.3s ease;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4e7f1 100%);
            min-height: 100vh;
            padding: 20px;
            color: var(--dark);
        }
        
        .container {
            width: 100%;
            max-width: 1400px;
            margin: 0 auto;
        }
        
        .header {
            text-align: center;
            margin-bottom: 30px;
            padding: 20px;
            background: white;
            border-radius: 12px;
            box-shadow: var(--card-shadow);
        }
        
        .header h1 {
            font-size: 2.5rem;
            color: var(--primary);
            margin-bottom: 10px;
            font-weight: 700;
        }
        
        .header p {
            font-size: 1.1rem;
            color: var(--gray);
            max-width: 700px;
            margin: 0 auto;
        }
        
        .toolbar {
            display: flex;
            justify-content: space-between;
            margin-bottom: 20px;
            background: white;
            padding: 15px 20px;
            border-radius: 12px;
            box-shadow: var(--card-shadow);
        }
        
        .btn-group {
            display: flex;
            gap: 15px;
        }
        
        .custom-btn {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 10px 18px;
            border-radius: 8px;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
            border: none;
            background: var(--primary);
            color: white;
        }
        
        .custom-btn i {
            font-size: 1.1rem;
        }
        
        .custom-btn:hover {
            opacity: 0.9;
            transform: translateY(-2px);
        }
        
        .btn-add {
            background: var(--primary);
        }
        
        .btn-edit {
            background: var(--warning);
        }
        
        .btn-delete {
            background: var(--danger);
        }
        
        .btn-generate {
            background: var(--success);
        }
        
        .table-container {
            background: white;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: var(--card-shadow);
            padding: 20px;
        }
        
        .table-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        
        .table-header h2 {
            font-size: 1.8rem;
            color: var(--primary);
        }
        
        .table-actions {
            display: flex;
            gap: 10px;
        }
        
        .search-box {
            position: relative;
            width: 300px;
        }
        
        .search-box input {
            width: 100%;
            padding: 10px 15px 10px 40px;
            border: 1px solid var(--border);
            border-radius: 8px;
            font-size: 1rem;
        }
        
        .search-box i {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--gray);
        }
        
        .footer {
            text-align: center;
            margin-top: 30px;
            padding: 20px;
            color: var(--gray);
            font-size: 0.9rem;
        }
        
        .config-preview {
            background: #2c3e50;
            color: #ecf0f1;
            border-radius: 8px;
            padding: 20px;
            font-family: 'Courier New', monospace;
            white-space: pre;
            overflow-x: auto;
            max-height: 500px;
            margin-top: 20px;
        }
        
        .config-key {
            color: #3498db;
        }
        
        .config-value {
            color: #2ecc71;
        }
        
        .config-comment {
            color: #7f8c8d;
        }
        
        @media (max-width: 768px) {
            .toolbar {
                flex-direction: column;
                gap: 15px;
            }
            
            .btn-group {
                flex-wrap: wrap;
            }
            
            .header h1 {
                font-size: 2rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1><i class="fas fa-tasks"></i> 模块化任务管理系统</h1>
            <p>管理您的自动化任务，创建、编辑和生成任务配置文件</p>
        </div>
        
        <div class="toolbar">
            <div class="btn-group">
                <button class="custom-btn btn-add" id="addTask">
                    <i class="fas fa-plus"></i> 添加任务
                </button>
                <button class="custom-btn btn-edit" id="editTask">
                    <i class="fas fa-edit"></i> 编辑任务
                </button>
                <button class="custom-btn btn-delete" id="deleteTask">
                    <i class="fas fa-trash"></i> 删除任务
                </button>
            </div>
            <button class="custom-btn btn-generate" id="generateConfig">
                <i class="fas fa-file-code"></i> 生成配置文件
            </button>
        </div>
        
        <div class="table-container">
            <div class="table-header">
                <h2><i class="fas fa-table"></i> 任务列表</h2>
                <div class="table-actions">
                    <div class="search-box">
                        <i class="fas fa-search"></i>
                        <input type="text" id="searchInput" placeholder="搜索任务...">
                    </div>
                </div>
            </div>
            
            <table class="layui-table" lay-filter="taskTable" id="taskTable">
                <colgroup>
                    <col width="40">
                    <col width="80">
                    <col width="200">
                    <col>
                    <col width="120">
                    <col width="180">
                    <col width="100">
                </colgroup>
                <thead>
                    <tr>
                        <th lay-data="{type:'checkbox'}">选择</th>
                        <th lay-data="{field:'id', sort:true}">序号</th>
                        <th lay-data="{field:'name'}">任务名称</th>
                        <th lay-data="{field:'command'}">执行命令</th>
                        <th lay-data="{field:'mode'}">执行模式</th>
                        <th lay-data="{field:'hosts'}">目标主机</th>
                        <th lay-data="{field:'status', templet:'#statusTpl'}">状态</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><input type="checkbox" name="task" value="1"></td>
                        <td>1</td>
                        <td>monitor_real_time_logs</td>
                        <td>timeout 60 tail -f /var/log/syslog</td>
                        <td>parallel</td>
                        <td>web-server-01, api-server-01</td>
                        <td><span class="layui-badge layui-bg-green">运行中</span></td>
                    </tr>
                    <tr>
                        <td><input type="checkbox" name="task" value="2"></td>
                        <td>2</td>
                        <td>check_disk_usage</td>
                        <td>df -h</td>
                        <td>serial</td>
                        <td>db-server-01, file-server-01</td>
                        <td><span class="layui-badge">未运行</span></td>
                    </tr>
                    <tr>
                        <td><input type="checkbox" name="task" value="3"></td>
                        <td>3</td>
                        <td>backup_database</td>
                        <td>mysqldump -u root -p dbname > backup.sql</td>
                        <td>serial</td>
                        <td>db-server-01</td>
                        <td><span class="layui-badge">未运行</span></td>
                    </tr>
                    <tr>
                        <td><input type="checkbox" name="task" value="4"></td>
                        <td>4</td>
                        <td>restart_nginx_service</td>
                        <td>systemctl restart nginx</td>
                        <td>parallel</td>
                        <td>web-server-01, web-server-02</td>
                        <td><span class="layui-badge layui-bg-green">运行中</span></td>
                    </tr>
                </tbody>
            </table>
        </div>
        
        <div class="footer">
            <p>© 2023 模块化任务管理系统 | 基于LayUI构建 | 共4个任务</p>
        </div>
    </div>
    
    <!-- 配置文件预览悬浮层 -->
    <div id="configPreviewModal" style="display:none; padding:20px;">
        <h2 style="margin-bottom:15px; color:#3498db;"><i class="fas fa-file-code"></i> 配置文件预览</h2>
        <p style="margin-bottom:20px;">以下是选中任务的YAML配置文件，您可以复制使用：</p>
        
        <div class="config-preview">
<span class="config-comment"># 任务配置 - 自动生成</span>
<span class="config-comment"># 生成时间: 2023-10-15 14:30:22</span>

<span class="config-key">tasks</span>:
  - <span class="config-key">name</span>: <span class="config-value">"monitor_real_time_logs"</span>                   <span class="config-comment"># 任务名称</span>
    <span class="config-key">command</span>: <span class="config-value">"timeout 60 tail -f /var/log/syslog"</span>    <span class="config-comment"># 执行命令</span>
    <span class="config-key">mode</span>: <span class="config-value">"parallel"</span>                                 <span class="config-comment"># 执行模式</span>
    <span class="config-key">timeout</span>: <span class="config-value">10</span>                                      <span class="config-comment"># 超时时间(秒)</span>
    <span class="config-key">hosts</span>:                                           <span class="config-comment"># 主机列表</span>
      - <span class="config-value">"web-server-01"</span>
      - <span class="config-value">"api-server-01"</span>
    <span class="config-key">expected</span>:                                        <span class="config-comment"># 期望输出</span>
      - <span class="config-value">"active (running)"</span>
    <span class="config-key">unexpected</span>:                                      <span class="config-comment"># 不期望输出</span>
      - <span class="config-value">"failed"</span>
    <span class="config-key">allow_failure</span>: <span class="config-value">true</span>                              <span class="config-comment"># 允许失败</span>

  - <span class="config-key">name</span>: <span class="config-value">"restart_nginx_service"</span>                   <span class="config-comment"># 任务名称</span>
    <span class="config-key">command</span>: <span class="config-value">"systemctl restart nginx"</span>               <span class="config-comment"># 执行命令</span>
    <span class="config-key">mode</span>: <span class="config-value">"parallel"</span>                                 <span class="config-comment"># 执行模式</span>
    <span class="config-key">timeout</span>: <span class="config-value">30</span>                                      <span class="config-comment"># 超时时间(秒)</span>
    <span class="config-key">hosts</span>:                                           <span class="config-comment"># 主机列表</span>
      - <span class="config-value">"web-server-01"</span>
      - <span class="config-value">"web-server-02"</span>
    <span class="config-key">depends_on</span>:                                      <span class="config-comment"># 依赖任务</span>
      - <span class="config-value">"monitor_real_time_logs"</span>
        </div>
        
        <div style="margin-top:20px; text-align:center;">
            <button class="custom-btn" style="margin-right:10px;" id="copyConfig">
                <i class="fas fa-copy"></i> 复制配置
            </button>
            <button class="custom-btn btn-generate" id="exportConfig">
                <i class="fas fa-download"></i> 导出文件
            </button>
            <button class="custom-btn btn-cancel" id="closeConfig">
                <i class="fas fa-times"></i> 关闭
            </button>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/layui@2.8.3/dist/layui.min.js"></script>
    <script src="main.js"></script>
</body>
</html>